package org.arrendar.kakeibo.config.taskqueue;

import java.util.List;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.arrendar.kakeibo.dao.KakeiboDao;
import org.arrendar.kakeibo.dto.MonthlyMoney;

public class Amend extends WebPage{

	public Amend(final PageParameters pram) {
		
		String User=pram.getString("User");
		String Year=pram.getString("Year");
		String Month=pram.getString("Month");
		String Money=pram.getString("Money");
		
		MonthlyMoney TotalMoney =  new MonthlyMoney(User,Integer.parseInt(Year),Integer.parseInt(Month),Integer.parseInt(Money));
		KakeiboDao dao =new KakeiboDao();
		List<MonthlyMoney> Result=dao.getMonthlyTotal(User,Integer.parseInt(Year),Integer.parseInt(Month));
		if(Result.size()>0){
			dao.UpdateMonthly(Result.get(Result.size()-1).getID(), Result.get(Result.size()-1).getTotalMoney()-Integer.parseInt(Money));
		}else{
			dao.MonthyTotalSave(TotalMoney);
		}
		
	}
}
